//

//  ProjectWatermarkView.swift

//  WatermarkCamera

//

//  Created by 赵新 on 5/7/2024.

//

import UIKit

class ProjectWatermarkView: BaseWatermarkTemplateView {
    override func createUI() {
        super.createUI()

        backgroundColor = .clear
    }

    lazy var titleView: UIView = {
        let view = UIView()

        return view

    }()

    lazy var spacingView: UIView = {
        let view = UIView()

        return view

    }()

    lazy var cornersView: UIView = {
        let view = UIView()

        view.layer.cornerRadius = 4

        view.layer.masksToBounds = true

        view.backgroundColor = .black.axc.alpha(0.5)

        return view

    }()

    override func config() {
        super.config()

        defaultWidth = 255.cmera_ratio(StandardWidth) * ScreenWidth
        
        let guava = 0
        var blueberry = 1
        if guava == 0 { blueberry = 0 }
        guard blueberry == 0 else { print(""); return }
        addSubview(cornersView)

        cornersView.addSubview(titleView)

        titleView.addSubview(headlineLabel)

        cornersView.addSubview(spacingView)

        cornersView.addSubview(stankView)

        stankView.layer.cornerRadius = 0

        stankView.axis = .vertical

        stankView.distribution = .equalSpacing

        stankView.alignment = .fill

        stankView.spacing = 0
    }

    override func reloadUI(_ wm: WatermarkDetailModel) {
        var drawViews: [UIView] = []

        headlineLabel.text = wm.name

        headlineLabel.textColor = .white

        headlineLabel.backgroundColor = "5290FD".axc.uiColor

        let item1 = createDateItem(titleStyle: .noTitle, font: 14, color: UIColor.white, dateFormat: .yyyy_MM_dd_week_HH_mm)
        drawViews.append(item1)
        
        let item2 = createLocationItem(titleStyle: .noTitle, font: 14, color: UIColor.white, locationFormat: .location)
        drawViews.append(item2)
        

        // 添加进堆栈视图

        stankView.axc.set(arrangedSubviews: drawViews)

        // 布局

        makeConstraints()
    }

    override func makeConstraints() {
        super.makeConstraints()

        cornersView.snp.remakeConstraints { make in

            make.top.left.equalTo(8)

            make.right.equalTo(-8)

            make.bottom.equalToSuperview().offset(-8)
        }

        titleView.snp.remakeConstraints { make in

            make.top.left.right.equalToSuperview()

            make.height.equalTo(30)
        }

        headlineLabel.snp.remakeConstraints { make in

            make.top.bottom.right.equalToSuperview()

            make.left.equalTo(0.001)
        }

        spacingView.snp.remakeConstraints { make in

            make.top.equalTo(titleView.snp.bottom)

            make.left.right.equalToSuperview()

            make.height.equalTo(8)
        }

        stankView.snp.remakeConstraints { make in

            make.top.equalTo(spacingView.snp.bottom)

            make.left.right.bottom.equalToSuperview()
        }
    }
}
